<script lang="ts" setup>
import { ref } from "vue";

const activeIndex = ref("1");
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};

//创建菜单对象
const menu = {
  items: [
    {
      name: "测试",
      path: "/",
      icon: "Search",
      subMenu: [
        {
          name: "文章页",
          path: "/single/308",
        },
        {
          name: "分类页",
          path: "/category/2",
        },
        {
          name: "存档页",
          path: "/archive",
        },
        {
          name: "搜索页",
          path: "/search",
        },
        {
          name: "过期页",
          path: "/expore",
        },
        {
          name: "404页",
          path: "/404",
        },

        {
          name: "测试页",
          path: "/test",
        },
      ],
    },
    {
      name: "个人中心",
      path: "/user",
      subMenu: [
        {
          name: "用户页",
          path: "/user",
        },
        {
          name: "登录页",
          path: "/login",
        },
      ],
    },
  ],
};
</script>
<template>
  <nav class="ac-localnav">
    <div class="ac-ln-wrapper">
      <div class="ac-ln-background"></div>
      <div class="ac-ln-content">
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          :ellipsis="false"
          @select="handleSelect"
          :router="true"
        >
          <el-menu-item index="/" class="logo-title"> AppleNews </el-menu-item>
          <div class="flex-grow" />

          <!--通过对象创建菜单-->
          <div v-for="(item, index) in menu.items" :key="index" class="menu">
            <!--进行判断 - 有子菜单-->
            <el-sub-menu
              v-if="item.subMenu && item.subMenu.length > 0"
              :index="item.path"
            >
              <template #title> {{ item.name }}</template>
              <el-menu-item
                v-for="(items, indexs) in item.subMenu"
                :key="indexs"
                :index="items.path"
                >{{ items.name }}</el-menu-item
              >
            </el-sub-menu>
            <!--进行判断 - 没有子菜单-->
            <el-menu-item v-else :index="item.path">
              {{ item.name }}
            </el-menu-item>
          </div>
        </el-menu>
      </div>
    </div>
  </nav>
</template>

<style lang="less" scoped>
.flex-grow {
  flex-grow: 1;
}
.ac-localnav {
  height: 3.6rem;
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  min-width: 1024px;
  z-index: 100;
}
.ac-ln-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  min-height: 100%;
  z-index: 1;
}
.ac-ln-background {
  background-color: rgba(255, 255, 255, 0.7);
  transition-property: backdrop-filter, -webkit-backdrop-filter,
    background-color;
  transition-timing-function: cubic-bezier(0.4, 0, 0.25, 1);
  transition-duration: 0.4s;
  transition-delay: 0s;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  backdrop-filter: saturate(180%) blur(20px);
}
.ac-ln-content {
  margin: 0 auto;
  max-width: 980px;
  padding: 0 22px;
  position: relative;
  z-index: 2;
  ul > {
    background-color: #ff000000;
    border-bottom: solid 1px #ff000000;
  }
}
//标题
.logo-title {
  font-size: 21px;
  line-height: 1.14286;
  font-weight: 600;
  margin: 14px 0 -14px;
  padding: 0;
}
.menu {
  margin-left: 28px;

  li {
    font-size: 12px;
    color: #1d1d1f;
    font-weight: 500;
  }
}

@media only screen and (max-width: 1044px) {
  .ac-localnav {
    min-width: 320px;
  }
}
@media only screen and (max-width: 767px) {
  .ac-localnav .ac-ln-content {
    padding: 0 16px;
  }
}
</style>
